package com.tuanzi.loan.business.repository.family.impl;

import com.tuanzi.loan.business.repository.family.custom.LoanNewCreditCardInfoRepositoryCustom;
import com.tuanzi.loan.core.repository.JOOQBaseRepository;
import com.tuanzi.loan.vo.request.family.LoanNewCreditCardInfoRequest;
import com.tuanzi.loan.vo.response.family.LoanNewCreditCardInfoResponse;
import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import static com.tuanzi.loan.generated.jooq.loan.tables.LoanNewCreditCardInfo.LOAN_NEW_CREDIT_CARD_INFO;

/**
 * User: liangZongXi
 * Create time: 18:03 2018/8/31
 * Description:
 */
public class LoanNewCreditCardInfoRepositoryImpl extends JOOQBaseRepository implements LoanNewCreditCardInfoRepositoryCustom {
    @Override
    public Page<LoanNewCreditCardInfoResponse> list(LoanNewCreditCardInfoRequest searchRequest, Pageable pageable) {
        fields(LOAN_NEW_CREDIT_CARD_INFO.fields());
        contains(LOAN_NEW_CREDIT_CARD_INFO.CARD_NAME,searchRequest.getName());
        return search(pageable, record -> {
            LoanNewCreditCardInfoResponse response = new LoanNewCreditCardInfoResponse();
            response.setId(record.get(LOAN_NEW_CREDIT_CARD_INFO.ID));
            response.setCardName(record.get(LOAN_NEW_CREDIT_CARD_INFO.CARD_NAME));
            response.setCardDesc(record.get(LOAN_NEW_CREDIT_CARD_INFO.CARD_DESC));
            response.setCardLabel(record.get(LOAN_NEW_CREDIT_CARD_INFO.CARD_LABEL));
            response.setListRebateLabel(record.get(LOAN_NEW_CREDIT_CARD_INFO.LIST_REBATE_LABEL));
            response.setDetailRebateLabel(record.get(LOAN_NEW_CREDIT_CARD_INFO.DETAIL_REBATE_LABEL));
            response.setSubTitle(record.get(LOAN_NEW_CREDIT_CARD_INFO.SUBTITLE));
            response.setRebateAmount(record.get(LOAN_NEW_CREDIT_CARD_INFO.REBATE_AMOUNT));
            response.setRightList(record.get(LOAN_NEW_CREDIT_CARD_INFO.RIGHT_LIST));
            response.setDegree(record.get(LOAN_NEW_CREDIT_CARD_INFO.DEGREE));
            response.setCardOrganization(record.get(LOAN_NEW_CREDIT_CARD_INFO.CARD_ORGANIZATION));
            response.setFreeDeadline(record.get(LOAN_NEW_CREDIT_CARD_INFO.FREE_DEADLINE));
            response.setIntegralRule(record.get(LOAN_NEW_CREDIT_CARD_INFO.INTEGRAL_RULE));
            response.setApplyCondition(record.get(LOAN_NEW_CREDIT_CARD_INFO.APPLY_CONDITION));
            response.setRedirectUrl(record.get(LOAN_NEW_CREDIT_CARD_INFO.REDIRECT_URL));
            response.setLogo(record.get(LOAN_NEW_CREDIT_CARD_INFO.LOGO));
            response.setInitApplyCount(record.get(LOAN_NEW_CREDIT_CARD_INFO.INIT_APPLY_COUNT));
            response.setSuccessApplyCount(record.get(LOAN_NEW_CREDIT_CARD_INFO.SUCCESS_APPLY_COUNT));
            response.setShowLabel(record.get(LOAN_NEW_CREDIT_CARD_INFO.SHOW_LABEL));
            response.setRedirectTipLabel(record.get(LOAN_NEW_CREDIT_CARD_INFO.REDIRECT_TIP_LABEL));
            response.setRemark(record.get(LOAN_NEW_CREDIT_CARD_INFO.REMARK));
            response.setCreator(record.get(LOAN_NEW_CREDIT_CARD_INFO.CREATOR));
            response.setCreateTime(record.get(LOAN_NEW_CREDIT_CARD_INFO.CREATE_TIME));
            response.setUpdator(record.get(LOAN_NEW_CREDIT_CARD_INFO.UPDATOR));
            response.setUpdateTime(record.get(LOAN_NEW_CREDIT_CARD_INFO.UPDATE_TIME));
            return response;
        });
    }

    @Override
    protected TableImpl getTable() {
        return LOAN_NEW_CREDIT_CARD_INFO;
    }
}
